/**
 * 
 */
package com.tompai.datagather.mail;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MailUtil {
	
	public static final Logger LOG = LoggerFactory.getLogger(MailUtil.class);
	
	private static String _USER_NAME_ = "test@163.com";
	private static String _PASSWORD_ = "test163test";
	private static String _SMTP_ADDRESS_ = "smtp.163.com";
	private final static int _SMTP_PORT_SSL_ = 994;
	private static String _FROM_MAIL_ = "test@163.com";

	public static void sendMail(String toAddress, String subject, String content) {
		Email email = new SimpleEmail();
		email.setHostName(_SMTP_ADDRESS_);
		email.setCharset("UTF-8");
		email.setSmtpPort(_SMTP_PORT_SSL_);
		email.setAuthenticator(new DefaultAuthenticator(_USER_NAME_, _PASSWORD_));
		email.setSSLOnConnect(true);
		try {
			email.setFrom(_FROM_MAIL_,"test");
			email.setSubject(subject);
			email.setMsg(content);
			email.addTo(toAddress);
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
}